<table id="admin_newscategorylist_datagrid" class="easyui-datagrid"
       data-options='
            "border":false,
            "fit":true,
            "fitColumns":true,
            "rownumbers":true,
            "singleSelect":true,
            "pagination":true,
            "pageList":[20,30,50,80,100],
            "pageSize":"20",
            "title":"新闻管理 > 新闻分类列表 ",
            "url":"/admin/news/news_category_list/datagrid",
            "method": "get",
            "toolbar":admin_newscategorylist_datagrid_toolbar' style="">
    <thead>
        <tr>
            <th data-options='"field":"category_name","width":30,"sortable":true'>分类名称</th>
            <th data-options='"field":"category_id","width":30,"formatter":adminnewscategorylistOperateFormatter'>管理操作</th>
        </tr>
    </thead>
</table>

<!-- 添加新闻分类 -->
<div id="admin_newscategorylist_add_dialog" class="easyui-dialog" title="添加分类" data-options="modal:true,closed:true,iconCls:'icons-application-application_add',buttons:[{text:'确定',iconCls:'icons-other-tick',handler:function(){$('#admin_newscategorylist_add_dialog_form').submit();}},{text:'取消',iconCls:'icons-arrow-cross',handler:function(){$('#admin_newscategorylist_add_dialog').dialog('close');}}]" style="width:480px;height:300px;"></div>

<!-- 编辑新闻分类 -->
<div id="admin_newscategorylist_edit_dialog" class="easyui-dialog" title="编辑分类" data-options="modal:true,closed:true,iconCls:'icons-application-application_edit',buttons:[{text:'确定',iconCls:'icons-other-tick',handler:function(){$('#admin_newscategorylist_edit_dialog_form').submit();}},{text:'取消',iconCls:'icons-arrow-cross',handler:function(){$('#admin_newscategorylist_edit_dialog').dialog('close');}}]" style="width:480px;height:300px;"></div>

<script type="text/javascript">
var admin_newscategorylist_datagrid_toolbar = [
	{ text: '添加分类', iconCls: 'icons-arrow-add', handler: adminnewscategorylistAdd },
	{ text: '刷新', iconCls: 'icons-arrow-arrow_refresh', handler: adminnewscategorylistRefresh }
];
//时间格式化
function adminnewscategorylistTimeFormatter(val){
	return val != '1970-01-01 08:00:00' ? val : '';
}
//状态格式化
function adminnewscategorylistStateFormatter(val){
	return val == 2 ? '<font color="red">草稿</font>' : '已发布';
}
//操作格式化
function adminnewscategorylistOperateFormatter(val){
	var btn = [];

    btn.push('<a href="javascript:void(0);" onclick="adminnewscategorylistEdit('+val+')">编辑</a>');
    btn.push('<a href="javascript:void(0);" onclick="adminnewscategorylistDelete('+val+')">删除</a>');

	return btn.join(' | ');
}
//刷新
function adminnewscategorylistRefresh(){
	$('#admin_newscategorylist_datagrid').datagrid('reload');
}
//添加
function adminnewscategorylistAdd(){
	$('#admin_newscategorylist_add_dialog').dialog({href:'/admin/news/news_category_add'});
	$('#admin_newscategorylist_add_dialog').dialog('open');
}
//编辑
function adminnewscategorylistEdit(id){
	if(typeof(id) !== 'number'){
		$.messager.alert('提示信息', '未选择新闻', 'error');
		return false;
	}
	var url = '/admin/news/news_category_edit';
	url += url.indexOf('?') != -1 ? '&id='+id : '?id='+id;
	$('#admin_newscategorylist_edit_dialog').dialog({href:url});
	$('#admin_newscategorylist_edit_dialog').dialog('open');
}
//删除
function adminnewscategorylistDelete(id){
	if(typeof(id) !== 'number'){
		$.messager.alert('提示信息', '未选择新闻', 'error');
		return false;
	}
	$.messager.confirm('提示信息', '确定要删除吗？', function(result){
		if(!result) return false;
		$.post('/admin/news/news_delete', {id: id}, function(res){
			if(!res.code){
				$.messager.alert('提示信息', res.msg, 'error');
			}else{
				$.messager.alert('提示信息', res.msg, 'info');
				adminRoleListRefresh();
			}
		}, 'json');
	});
}

</script>